using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.Components;
using System.Windows.Forms;

namespace MacomberMap.Common.Events
{
    /// <summary>
    /// This class holds event information for a duplicate item
    /// </summary>
    public class MM_Event_DuplicateValue: MM_Event
    {
        /// <summary>
        /// The element that would be added in
        /// </summary>
        public Object DuplicateElement;

        /// <summary>
        /// The existing element
        /// </summary>
        public Object ExistingElement;

        /// <summary>
        /// The member that is causing the conflict
        /// </summary>        
        public String ConflictMember;

        /// <summary>
        /// Instantiate a new duplicate value error
        /// </summary>
        /// <param name="ExistingElement">The existing element</param>
        /// <param name="DuplicateElement">The element that can't be added due to duplication</param>
        /// <param name="ConflictMember">The member causing the conflict</param>
        public MM_Event_DuplicateValue(Object ExistingElement, Object DuplicateElement, String ConflictMember)
        {
            this.ExistingElement = ExistingElement;
            this.DuplicateElement = DuplicateElement;
            this.ConflictMember = ConflictMember;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutMenu"></param>
        public override void AddMenuItems(System.Windows.Forms.ContextMenuStrip OutMenu)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ListViewItem BuildListViewItem()
        {
            ListViewItem OutItem = new ListViewItem(ConflictMember + ": " + ExistingElement.ToString() + " and " + DuplicateElement.ToString());
            OutItem.SubItems.Add(EventState.ToString());
            OutItem.SubItems.Add(TimeText);
            OutItem.Tag = this;
            return OutItem;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutParent"></param>
        public override void DisplayDetails(System.Windows.Forms.Control OutParent)
        {
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lvItem"></param>
        public override void UpdateListViewItem(ListViewItem lvItem)
        {
            lvItem.SubItems[0].Text = ConflictMember + ": " + ExistingElement.ToString() + " and " + DuplicateElement.ToString();
            lvItem.SubItems[1].Text = EventState.ToString();
            lvItem.SubItems[2].Text = TimeText;
        }

        /// <summary>
        /// Compare two duplicate value elements
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            return ConflictMember.CompareTo((obj as MM_Event_DuplicateValue).ConflictMember);            
        }
    }
}
